﻿using MvvmOrm.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;

namespace MvvmOrm.Tests
{
    [TestClass()]
    public class MainViewModelTest
    {
        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void OpenNewTest()
        {
            Models.MainViewModel mainViewModel = new Models.MainViewModel();
            Assert.IsFalse(mainViewModel.IsOpen);
            Assert.IsTrue(mainViewModel.OpenNewCmd.CanExecute());
            mainViewModel.OpenNewCmd.Execute();
            Assert.IsFalse(mainViewModel.OpenNewCmd.CanExecute());
            Assert.IsTrue(mainViewModel.IsOpen);
            Assert.IsTrue(mainViewModel.IsNew);
            mainViewModel.CloseCmd.Execute();
        }

        [TestMethod()]
        public void CloseTest()
        {
            Models.MainViewModel mainViewModel = new Models.MainViewModel();
            Assert.IsFalse(mainViewModel.CloseCmd.CanExecute());
            mainViewModel.OpenNewCmd.Execute();
            Assert.IsFalse(mainViewModel.OpenNewCmd.CanExecute());
            Assert.IsTrue(mainViewModel.CloseCmd.CanExecute());
            mainViewModel.CloseCmd.Execute();
            Assert.IsFalse(mainViewModel.IsOpen);
        }

        [TestMethod()]
        public void OpenTest()
        {
            Models.MainViewModel mainViewModel = new Models.MainViewModel();
            Assert.IsFalse(mainViewModel.IsOpen);
            Assert.IsTrue(mainViewModel.OpenCmd.CanExecute(null));
            mainViewModel.OpenCmd.Execute(Common.SavedFile);
            Assert.IsTrue(mainViewModel.IsOpen);
            Assert.IsFalse(mainViewModel.IsNew);
            mainViewModel.CloseCmd.Execute();
        }

        [TestMethod()]
        public void SaveTest()
        {
            Models.MainViewModel mainViewModel = new Models.MainViewModel();
            Assert.IsFalse(mainViewModel.SaveCmd.CanExecute(false));
            mainViewModel.OpenCmd.Execute(Common.SavedFile);
            Assert.IsFalse(mainViewModel.SaveCmd.CanExecute(false));
            mainViewModel.DB.UseSchemaFile = !mainViewModel.DB.UseSchemaFile;
            Assert.IsTrue(mainViewModel.SaveCmd.CanExecute(false));
            mainViewModel.SaveCmd.Execute(false);
            Assert.IsFalse(mainViewModel.SaveCmd.CanExecute(false));
            mainViewModel.DB.UseSchemaFile = !mainViewModel.DB.UseSchemaFile;
            Assert.IsTrue(mainViewModel.SaveCmd.CanExecute(false));
            mainViewModel.SaveCmd.Execute(false);
            mainViewModel.CloseCmd.Execute();
        }
    }
}
